package game;
import java.io.Serializable;
import java.util.Random;

import org.apache.log4j.*;

public class Player implements Serializable
{

	private static final long serialVersionUID = -3151110742934422622L;
	
	private double bankroll;
	private long id;
	private static Logger playerLogger = Logger.getLogger(Player.class);
	
	public long getID() {
		return id;
	}

	public Player(double initialBankroll)
	{
		setBankroll(initialBankroll);
		playerLogger.setLevel(Level.DEBUG);
		Random ran  = new Random();
		this.id = ran.nextLong();
	}

	public double getBankroll() {
		return bankroll;
	}

	private void setBankroll(double bankroll) {
		this.bankroll = bankroll;
	}
	
	//giveWinnings
	//@param position the bet which paid the money
	//@param amount the amount won (should not include the original bet)
	public void giveWinnings(BetPosition position, double amount)
	{
		receiveMoney(amount);
		playerLogger.debug(id + ": yay I won " + amount + " by betting on " + position);
	}
	
	//notifyLoss
	//@param position of the bet
	//@param amount lost
	public void notifyLoss(BetPosition position, double amount)
	{
		//for use once the computer is playing (allows decisions based on lost bets
	}
	
	
	//recieveMoney
	//@param amount amount of money to receive and add to bankroll
	//This method is to be used to give the player money not associated with any bet "Winning"
	//  e.g. reducing the amount of money on a particular bet
	public void receiveMoney(double amount)
	{
		bankroll += amount;
	}
	//TakeBet
	//@param amount the amount of money to place on the bet.  The total placed is Min(amount,bankroll).
	public double giveMoney(double amount)
	{
		double moneyplaced = 0;
		//Yes I know I could use Min here, but trinary operator felt better :)
		moneyplaced = (amount < bankroll) ? amount : bankroll;
		bankroll -= moneyplaced;
		return moneyplaced;
	}
}
